import analisadorWave
import threading
import wave
import sys

class ExecutorAnalise(threading.Thread):
	
	__identificador = 0
	def __init__(self,wavefile):
		ExecutorAnalise.__identificador += 1
		self.terminou = False
		self.analise = analisadorWave.AnalisadorWave(wavefile)
		self.printed = False
		threading.Thread.__init__(self)
		
	def run(self):
		self.terminou = False
		self.printed = False
		self.analise.analisar()
		self.terminou = True
		
	def getId(self):
		return self.__identificador
	
########################################################
###########					TESTER					###########

if __name__ == '__main__':
	
	exe1 = ExecutorAnalise(wave.open('/tmp/recEsq.wav'))
	exe2 = ExecutorAnalise(wave.open('/tmp/recDir.wav'))
	print 'Analisando os dois sons...'
	exe1.start()
	exe2.start()
	i = 0
	while not(exe1.terminou and exe2.terminou):
		if exe1.terminou and ( i==0 ):
			print "Analise 1 completou primeiro"
			i = 1
		if exe2.terminou and (i==0 ):
			print "Analise 2 completou primeiro"
			i = 2
		
	print 'Terminou a analise'
	print 'Analise 1'
	exe1.analise.imprimeResultados()
	print 'Analise 2'
	exe2.analise.imprimeResultados()
	
